extends IRangeAttribute


class_name RangeAttribute


## 可调用接口
enum Method {
    None,     ## 不执行任何操作
    Increase, ## 增加值
    Decrease, ## 减少值
    Done,     ## 消耗所有值
    Full,     ## 充满所有值
    Set,      ## 设置值
    SetMin,   ## 设置最小值
    SetMax,   ## 设置最大值
}


func __set_value(property: String, new_value: int) -> int:
    match property:
        "value":
            return clampi(new_value, min_value, max_value)
        "max":
            # 不做修改
            if new_value <= min_value:
                return max_value
            if value > new_value:
                value = new_value
        "min":
            # 不做修改
            if new_value <= max_value:
                return min_value
    return new_value

# 是否已经消耗完
func is_done() -> bool:
    return value <= min_value

# 是否为满容状态
func is_full() -> bool:
    return value >= max_value

# 返回当前剩余容量
func capacity() -> int:
    return value - min_value

# 返回当前的空余量
func space() -> int:
    return max_value - value

# 受伤
func decrease(decrement: int) -> void:
    value = value - decrement

# 回复
func increase(increment: int) -> void:
    value = value + increment

# 清空值,返回扣除的值
func done() -> void:
    value = min_value

# 充满值,返回恢复的值
func full() -> void:
    value = max_value

# 执行指定的动作
func execute(method: Method, value: int) -> void:
    match method:
        Method.None: pass
        Method.Increase: increase(value)
        Method.Decrease: decrease(value)
        Method.Done: done()
        Method.Full: full()
        Method.Set: self.value = value
        Method.SetMin: min_value = value
        Method.SetMax: max_value = value
